package com.qf.fmall.orders.controller;

import com.qf.fmall.orders.entity.Orders;
import com.qf.fmall.orders.service.IOrdersService;
import com.qf.fmall.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 订单  前端控制器
 * </p>
 *
 * @author weijy
 * @since 2024-01-18
 */
@CrossOrigin
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private IOrdersService ordersService;

    @RequestMapping("/add")
    public ResultVo add(@RequestParam List<String> cids, @RequestBody Orders orders) throws ParseException {

        HashMap<String, Object> data = ordersService.addOrders(cids, orders);

        return new ResultVo(10000, "success", data);
    }

    @RequestMapping("/status/{orderId}")
    public ResultVo status(@PathVariable("orderId") String orderId) {

        boolean flag = ordersService.getStatus(orderId);

        if (flag) {
            return new ResultVo(10000, "success", 2);
        } else {
            return new ResultVo(10000, "success", -1);
        }
    }


}
